所有Kotlin類別都有共通的superclass Any
Any內有定義三個方法equals()、hashCode()以及toString()
覆寫方法
如下對於Circle.draw()而言,override這個修飾詞是必要的;若省略則編譯器會出現錯誤
open class Shape {
open fun draw() { /*...*/ }
fun fill() { /*...*/ }
}
class Circle() : Shape() {
override fun draw() { /*...*/ }
}
open class Shape {
open val vertexCount: Int = 0
}
class Rectangle : Shape() {
override val vertexCount = 4
}